<?php

declare (strict_types=1);

namespace App\Model;

/**
 * @property int $id
 * @property int $uid
 * @property int $work_day
 * @property int $start
 * @property int $end
 * @property int $status
 * @property int $create_time
 */
class WorkDate extends Model
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'work_date';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $guarded = [];
    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = ['id' => 'integer', 'uid' => 'integer', 'work_day' => 'integer', 'start' => 'integer', 'end' => 'integer', 'status' => 'integer', 'create_time' => 'integer'];

    public static function workDateList($uid)
    {
        $today = strtotime(date('Y-m-d', time()));
        $scheduleArr = [];
        $scheduleKeyArr = [];

        $nextDay = $today;
        for ($i = 0; $i < 7; $i++) {
            $scheduleArr[] = $nextDay;
            $scheduleKeyArr[$nextDay] = null;
            $nextDay += 86400;
        }

        $workDateList = WorkDate::whereIn('work_day', $scheduleArr)->where(['uid'=>$uid])->get()->toArray();


        foreach ($workDateList as $k => $v) {
            $scheduleKeyArr[$v['work_day']] = $v;
        }

        ksort($scheduleKeyArr);

        $list = [];
        foreach ($scheduleKeyArr as $k => $v) {
            $list[] = [
                'workDay' => $k,
                'info' => $v
            ];
        }

        return $list;
    }


}